package org.bridgen.runtime.model;

import org.bridgen.runtime.util.Interval;

/**
 * 
 * @author Emma Söderberg <emma add cs.lth.se>
 *
 */

public abstract class LayoutReef extends Reef {

	/**
	 * Creates a new LayoutReef
	 * @param previous The previous node in the token list
	 * @param interval The corresponding interval
	 * @param value The corresponding value
	 */
	public LayoutReef(LexicalNode previous, Interval interval, String value) {
		super(previous, interval, value);
	}

	/*
	 * Attribute: int LayoutReef.pos
	 * The tab size needs to be adjusted to the most suitable one
	 */
	public int TAB_SIZE = 4;
	private int pos = -1;
	public int pos() {
		if (pos < 0) {
			char[] chars = value.toCharArray();
			for (int i = 0; i < chars.length; i++) {
				switch(chars[i]) {
					case ' '  : pos++; break;
					case '\t' : pos += TAB_SIZE; break;
				}
			}
		}
		return pos;
	}
	
}
